//
//  ViewController.swift
//  client
//
//  Created by 我演示 on 2019/11/8.
//  Copyright © 2019 ALLSall. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    fileprivate lazy var socket:FSLSocket = FSLSocket(addr: "192.168.33.25", port: 7878)
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        if socket.connectServer() {
            print("接收到一个客户端连接")
        }
        // Do any additional setup after loading the view.
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

        let message = "nihao"
        let data = message.data(using: .utf8)!
        var length = data.count
        
        //2: 讲消息长度，写入到data
        let headerData = Data(bytes: &length, count: 4)
        
        print(data.count)
        let totalData = headerData + data
        
        socket.sendMsg(data: totalData)
        //        let data = Data(base64Encoded: <#T##String#>)
    }


}

